<?php

$objXajax->registerFunction("frmmenu_loadGrid");
$objXajax->registerFunction("frmmenu_save");
$objXajax->registerFunction("frmmenu_edit");

function frmmenu_save($params){
 global $objDbUpdate;
 $objResponse = new xajaxResponse(); 
 $name_vi = addslashes($params['txtViMenu']);
 $name_en = addslashes($params['txtEnMenu']);
 $icon = addslashes($params['txtIcon']);
 $ordershow = $params['txtOrdershow'];
 //$chkShareSub = $params['chkShareSub'];
// $chkMenudactrung = $params['chkMenu-dactrung'];
// $servicetype = $params['servicetype'];
 $edit = $params['hdEdit'];
 $id = $params['hdId'];
// $customer_type = $chkMenudactrung==0?0:$servicetype;

 if($edit!=1){
   $sqlInsert = "INSERT INTO tbl_main_menu_cus(name_vi,name_en,icon,active,ordershow) VALUE('$name_vi','$name_en','$icon','0','$ordershow')";
   
   $result    =  $objDbUpdate->Execute($sqlInsert);
     $arrPower  = $params['arrPower'];
     $id_insert = mysql_insert_id();
     $objResponse->addScript("changeUpdate('frmmenu',$id_insert);");     
 }else{
     $sql = "UPDATE tbl_main_menu_cus SET name_vi ='$name_vi',name_en ='$name_en',icon ='$icon',ordershow='$ordershow' WHERE id = '$id'";
    if($objDbUpdate->Execute($sql)){
    }
     
 }
// echo $sql; die();
 $objResponse->addScript('xajax_frmmenu_loadGrid();');
 $objResponse->addScript('changeWaiting(1);');
 return   $objResponse->getXML($sqlInsert);
}

function frmmenu_loadGrid(){   
    global $lang,$objDbSelect,$path;
    $lang ='vi';
    $arrMenu = frmmenu_GetMenu();
    $objResponse = new xajaxResponse();
    $oTbs = new clsTinyButStrong();
    $oTbs->LoadTemplate('templates/'.$lang.'/'.$path.'/main_menu_grid.html');
    $oTbs->MergeBlock('blk_data', $arrMenu);
    $oTbs->Show(TBS_NOTHING);
    $objResponse->addAssign('frmmenu_divGrid', 'innerHTML', $oTbs->Source); 
    $objResponse->addScriptCall("dataTableObj.CreatDataTable('frmmenu_tbl');");                             
    $objResponse->addScript('changeWaiting(1);');  
    return $objResponse->getXML();
}

function  frmmenu_GetMenu(){
    global $objDbSelect,$lang;
    $sqlSelect = " select c.* from tbl_main_menu_cus c  order by ordershow  ";
    return $objDbSelect->GetArray($sqlSelect);
}

function  frmmenu_edit($id){
    global $objDbSelect;
    $objResponse = new xajaxResponse();
    $sql         = "select * from tbl_main_menu_cus where id = '$id'";
    $arrMenu         = $objDbSelect->GetArray($sql);
    
   //  $sql         = "select * from tbl_mainmenu_powertype where main_menu_id = '$id'";
   //  $arrPower         = $objDbSelect->GetArray($sql);            
    $name_vi = $arrMenu[0]['name_vi'];
    $name_en = $arrMenu[0]['name_en'];
    $icon    = $arrMenu[0]['icon'];
    $ordershow    = $arrMenu[0]['ordershow'];
    //$customer_type    = $arrMenu[0]['customer_type'];
    //$customer_security    = $arrMenu[0]['customer_security'];
    $strId = ''; 
    //echo    $customer_type; die();
/*    if($customer_type!=0){
        $objResponse->addScript("$('#frmmenu_trServicetype').css('display','');"); 
        $objResponse->addScript("$('#frmmenu_servicetype-$customer_type').attr('checked','checked');"); 
        $objResponse->addScript("$('#frmmenu_chkMenu-dactrung').attr('checked','checked');"); 
    }else{
         $objResponse->addScript("$('#frmmenu_chkMenu-dactrung').attr('checked',false);");
        $objResponse->addScript("$('#frmmenu_trServicetype').css('display','none');"); 
    } */
/*    if($customer_security==1){
        $objResponse->addScript("$('#frmmenu_chkShareSub').attr('checked','checked');"); 
    }else{
        $objResponse->addScript("$('#frmmenu_chkShareSub').attr('checked',false);"); 
    }  */   
    
    $objResponse->addScript("$('#frmmenu_txtViMenu').val('$name_vi');");
    $objResponse->addScript("$('#frmmenu_txtEnMenu').val('$name_en');");
    $objResponse->addScript("$('#frmmenu_txtIcon').val('$icon');");
    $objResponse->addScript("$('#frmmenu_txtOrdershow').val('$ordershow');");
  
    $objResponse->addScript('changeWaiting(1);');
    
    return $objResponse->getXML();
}   
 
  # end region process data
?>
